<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Company_model extends MY_Model
{
    public function __construct() {
        parent::__construct();
    }

    public function getServiceInfo($companyid,$filds = " * ")
    {

        $sql = "SELECT {$filds} FROM yy_company_contact WHERE isDel=0 AND companyid={$companyid} ORDER BY id DESC";
        $query = $this->db->query($sql);
        return $query->result_array();        
    }

    public function get_company_by_id($companyid,$filds=" * ")
    {
        $sql = "SELECT {$filds} FROM yy_company WHERE isDel=0 AND companyid={$companyid}";
        $query = $this->db->query($sql);
        return $query->row_array();
    }

    public function get_item_list($companyid = 0, $filds = " * ")
    {

        $sql = "SELECT {$filds} FROM yy_item WHERE isDel=0 AND companyid = {$companyid} ORDER BY onlinestatus desc, addtime DESC";
        $query = $this->db->query($sql);
        return $query->result_array();        
    }

//根据ids获取三级分类
    public function get_cat_list_by_ids($categoryid_str, $fields = "*")
    {
        $sql = "SELECT {$fields} FROM yy_item_category WHERE p_level =3 AND cat_id in (SELECT parent_id FROM yy_item_category WHERE p_level = 4 AND cat_id in ({$categoryid_str}))";
        $query = $this->db->query($sql);
        return $query->result_array();        
    }

}

